package com.agger.eurekacommonapi.exception;

import com.agger.eurekacommonapi.enums.CommonExceptionEnums;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @classname: BusinessRuntimeException
 * @description: 自定义业务运行时异常
 * @author chenhx
 * @date 2020-05-26 11:19:47
 */
@Data
@NoArgsConstructor
public class BusinessRuntimeException extends RuntimeException{

    private String applicationName;
    private String message;
    private CommonExceptionEnums exceptionEnums;
    private String exceptionDesc;

    public BusinessRuntimeException(String applicationName,String message,Throwable throwable){
        super(message,throwable);
        this.applicationName = applicationName;
        this.message = message;
        this.exceptionEnums = CommonExceptionEnums.ERROR_COMMON;
        this.exceptionDesc = String.format("服务[%s]异常：{错误编码:%s,错误信息:%s}",this.applicationName,this.exceptionEnums.code(),this.message);
    }

    public BusinessRuntimeException(String applicationName,CommonExceptionEnums enums){
        new BusinessRuntimeException(applicationName,enums,enums.desc());
    }

    public BusinessRuntimeException(String applicationName,CommonExceptionEnums enums,String message){
        super(message);
        this.applicationName = applicationName;
        this.message = message;
        this.exceptionEnums = enums;
        this.exceptionDesc = String.format("服务[%s]异常：{错误编码:%s,错误信息:%s}",this.applicationName,this.exceptionEnums.code(),this.message);
    }

}
